<?php

namespace app\api\model;

use app\common\model\BaseModel;
use think\Model;

class UserFile extends BaseModel
{
    public function teacher()
    {
        return $this->hasOne(Teacher::class, 'teacher_id', 'teacher_id')->field('teacher_id, nickname, headeravatar');
    }
    /**
     * 用户课件
     */
    public static function getFilesByUserId($userId, $size = 20)
    {
        return self::with(['teacher' => function ($query) {
            $query->with(['teacherCourse' => function ($query) {
                $query->with(['language', 'grade']);
            }]);
        }])->where('user_id', $userId)->order('createtime desc')->paginate($size);
    }
}
